package models

import (
	"github.com/jinzhu/gorm"
	db2 "meituan/db"
	"time"
)

type Activity struct {
	gorm.Model
	// 活动名称  例如 满35减15  满50减20
	Name string `form:"Name"  binding:"required"`
	// 活动类型  1满减 其他待定
	Type int `form:"Type"  binding:"required"`
	// 满减阈值
	ThresholdPrice float64 `gorm:"type:decimal(10,4)"`
	// 减多少
	Discount float64 `gorm:"type:decimal(10,4)" form:"Discount" binding:"required"`
	// 是否开始活动 1 不开始 2开始
	Status int `form:"Status"  binding:"required"`
	// 结束日期
	EndTime time.Time `form:"EndTime"  binding:"required"`
	ShopID  int       `form:"ShopID"  binding:"required"`
	Shop    Shop
}

func (activity Activity) TableName() string {
	return "activity"
}

func NewActivity() *Activity {
	return &Activity{
		Type:   1,
		Status: 2,
	}
}

func init() {
	db, _ := db2.NewDB()
	defer db.Close()
	db.AutoMigrate(new(Activity))
}
